﻿@inherits Mindfor.WebMP.Mvc.Views.RazorViewPage<Callback>
<script type="text/javascript">
	$().ready(function () {
		$("#CallbackFormPhone").focus(function () {
			$(this).removeClass("hint");
		});
		$("#CallbackFormPhone").mask("+7 (999) 999-99-99");

		$("#CallbackPostForm").ajaxForm(
			{
				success: submitSuccess,
				beforeSubmit: beforeSubmitValidation
			}
		);

		function submitSuccess(data) {
			if (!data.Success)
				$("#CallbackMessage").addClass("red");
			else
				$("#CallbackMessage").addClass("green");
			$("#SendingCallback").hide();
			$("#CallbackMessage").text(data.Message);
			$("#CallbackMessage").show();
			$("input[name='Name']").val('');
			$("input[name='Phone']").val('');
		};

		function beforeSubmitValidation(formData, jqForm, options) {
			var form = jqForm[0];
			var re = new RegExp('^\\+7 \\(\\d\\d\\d\\) \\d\\d\\d-\\d\\d-\\d\\d$');
			if (!form.Name.value || !re.test(form.Phone.value)) {
				return false;
			}

			$("#SendingCallback").show();
			$("#CallbackMessage").text('');
			$("#CallbackMessage").hide();
			$("#CallbackMessage").removeClass("red").removeClass("hint");
			return true;
		};
	});
</script>

<div class="callbackPostContainer">
@using (Html.BeginForm("CallbackPost", "Callback", FormMethod.Post, new { id = "CallbackPostForm", style="width: 250px;" }))
{
	<label for="Name">Имя:</label><br />
	@Html.TextBoxFor(m => m.Name, new { style="width: 200px;" }) @Html.ValidationMessageFor(m => m.Name)<br />
	<input type="text" class="invisible" name="Antibot" />
	<label for="CallbackFormPhone">Номер телефона:</label><br />
	@Html.TextBoxFor(m => m.Phone, new { id = "CallbackFormPhone", style = "width: 200px;" })
	@Html.ValidationMessageFor(m => m.Phone)
	<div class="buttons">
		<input type="submit" value="Отправить" />
	</div>
	<p id="SendingCallback" class="invisible"><img alt='' src='/Content/Icons/Load.gif'/>&nbsp;Отправляем ваш запрос...</p>
	<p id="CallbackMessage" class="invisible"></p>
 }
</div>